﻿//===============================================================================
//	LuaGlue.cpp
//	LUA -> C++接口管理器
//===============================================================================
#include <boost/uuid/uuid.hpp>            // uuid class
#include <boost/uuid/uuid_generators.hpp> // generators
#include <boost/uuid/uuid_io.hpp>         // streaming operators etc.
#include <sstream>

#include "LuaGlue.h"
#include "../share/LuaGlueCommon.h"


#include "../../3rd/lua_5.1/src/lua.hpp"
#include "../../3rd/libjson/json.h"

#include "LuaManager.h"
#include "../share/user_define.h"
#include "Mission.h"

#include "MissionDialogue.h"
#include "Player.h"
#include "ManagerHelper.h"

#include "MapSlot.h"

#include "PlayerDataStruct.inl"

#include "PlayerTemporaryDataDefinition.h"

#include "TaskRewardTable.h"
#include "Map.h"

#include "script_define.h"
#include "message_code.h"
#include "../share/GameHostManager.h"
#include "scene_logic.h"
#include "../share/random_mgr.h"
#include "../share/time_module.h"


//-------------------------------------------------------------------------------
int32_t Send2C_PlayerEnterScene(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "Send2C_PlayerEnterScene");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Send2C_PlayerEnterScene");
	MacroIsNumber(ls, ++_pos, "Send2C_PlayerEnterScene");
	MacroIsNumber(ls, ++_pos, "Send2C_PlayerEnterScene");
	MacroIsNumber(ls, ++_pos, "Send2C_PlayerEnterScene");
	MacroIsNumber(ls, ++_pos, "Send2C_PlayerEnterScene");


	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _scene_id = MacroGetIntegerArgument(ls, ++_pos);
	double _pos_x = MacroGetNumberArgument(ls, ++_pos);
	double _pos_y = MacroGetNumberArgument(ls, ++_pos);
	double _pos_z = MacroGetNumberArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player == nullptr)
	{
		return 0;
	}

	_player->Send2CEnterScene(_scene_id, _pos_x, _pos_y, _pos_z);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Send2C_PlayerLeaveScene(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Send2C_PlayerLeaveScene");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Send2C_PlayerLeaveScene");
	MacroIsNumber(ls, ++_pos, "Send2C_PlayerLeaveScene");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _scene_id = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player == nullptr)
	{
		return 0;
	}

	_player->Send2CLevelScene(_scene_id);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Bufer_SetFixedBitValue(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "Bufer_SetFixedBitValue");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedBitValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedBitValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedBitValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedBitValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedBitValue");

	_pos = 0;
	int32_t _pid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t start = MacroGetIntegerArgument(ls, ++_pos);
	int32_t size = MacroGetIntegerArgument(ls, ++_pos);
	int32_t value = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_pid);
	if (_player != nullptr)
	{
		_player->SetFixedBitValue(idx, start, size, value);

		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}


//-------------------------------------------------------------------------------
int32_t Bufer_GetFixedBitValue(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 4, "Bufer_GetFixedBitValue");
	//(uint16_t idx, uint16_t start, uint16_t size);
	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Bufer_GetFixedBitValue");
	MacroIsNumber(ls, ++_pos, "Bufer_GetFixedBitValue");
	MacroIsNumber(ls, ++_pos, "Bufer_GetFixedBitValue");
	MacroIsNumber(ls, ++_pos, "Bufer_GetFixedBitValue");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t start = MacroGetIntegerArgument(ls, ++_pos);
	int32_t size = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		uint32_t _iVal = _player->GetFixedBitValue(idx, start, size);

		MacroPushInteger(ls, _iVal);
		return 1;
	}

	MacroPushInteger(ls, -1);
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}


//-------------------------------------------------------------------------------
int32_t Bufer_SetFixedValue(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "Bufer_SetFixedValue");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedValue");

	_pos = 0;
	int32_t _pid = (int32_t)MacroGetNumberArgument(ls, ++_pos);
	int32_t idx = (int32_t)MacroGetNumberArgument(ls, ++_pos);
	uint32_t value = (uint32_t)MacroGetNumberArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_pid);
	if (_player != nullptr)
	{
		_player->SetFixedValue(idx, value);

		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}


//-------------------------------------------------------------------------------
int32_t Bufer_GetFixedValue(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Bufer_GetFixedValue");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Bufer_GetFixedValue");
	MacroIsNumber(ls, ++_pos, "Bufer_GetFixedValue");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t idx = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		uint32_t _iVal = _player->GetFixedValue(idx);
		MacroPushInteger(ls, _iVal);
		return 1;
	}

	MacroPushInteger(ls, -1);
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

int32_t Bufer_SetFixedValueByPlayerId(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "Bufer_SetFixedValue");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedValue");
	MacroIsNumber(ls, ++_pos, "Bufer_SetFixedValue");

	_pos = 0;
	int32_t playerId = (int32_t)MacroGetNumberArgument(ls, ++_pos);
	int32_t idx = (int32_t)MacroGetNumberArgument(ls, ++_pos);
	uint32_t value = (uint32_t)MacroGetNumberArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(playerId);
	if (_player != nullptr)
	{
		_player->SetFixedValue(idx, value);

		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Reward_DataStart(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Reward_DataStart");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Reward_DataStart");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		RewardData* _md = _player->GetRewardData();
		if (_md != nullptr)
		{
			_md->RewardDataStart();

			return 0;
		}
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Reward_DataSet(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "Reward_DataSet");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Reward_DataSet");
	MacroIsNumber(ls, ++_pos, "Reward_DataSet");
	MacroIsNumber(ls, ++_pos, "Reward_DataSet");
	MacroIsNumber(ls, ++_pos, "Reward_DataSet");
	MacroIsNumber(ls, ++_pos, "Reward_DataSet");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _type = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _prop_id = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _prop_num = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		RewardData* _ms = _player->GetRewardData();
		if (_ms != nullptr)
		{
			_ms->SetRewardType(_type);
			_ms->SetRewardInfoByIndex((_idx - 1), _prop_id, _prop_num);

			return 0;
		}
	}

	//MacroPushInteger(ls, -1);
	//return 1;
	return 0;

	_safe_guard_end;

	//MacroPushInteger(ls, -1);
	//return 1;
	return 0;
}

//-------------------------------------------------------------------------------
int32_t Reward_DataFinished(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Reward_DataFinished");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Reward_DataFinished");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		RewardData* _ms = _player->GetRewardData();
		if (_ms != nullptr)
		{
			_ms->RewardDataFinish();

			return 0;
		}
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Reward_DataToClient(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Reward_DataToClient");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Reward_DataToClient");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		_player->SendRewardDataToClient();

		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MsgCommon_DataStart(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "MsgCommon_DataStart");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommon_DataStart");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		NoticeCommon* _md = _player->GetNoticeData();
		if (_md != nullptr)
		{
			_md->NoticeStart();

			return 0;
		}
	}
	
	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MsgCommon_DataSet(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 7, "MsgCommon_DataSet");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommon_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommon_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommon_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommon_DataSet");
	MacroIsString(ls, ++_pos, "MsgCommon_DataSet");
	MacroIsString(ls, ++_pos, "MsgCommon_DataSet");
	MacroIsString(ls, ++_pos, "MsgCommon_DataSet");
	

	_pos = 0;
	uint32_t _uid = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	uint32_t _v1 = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	uint32_t _v2 = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	uint32_t _v3 = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	const char* _s1 = MacroGetStringArgument(ls, ++_pos);
	const char* _s2 = MacroGetStringArgument(ls, ++_pos);
	const char* _s3 = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		NoticeCommon* _md = _player->GetNoticeData();
		if (_md != nullptr)
		{
			_md->SetUserVal1(_v1);
			_md->SetUserVal2(_v2);
			_md->SetUserVal3(_v3);
			_md->SetOption1(_s1);
			_md->SetOption2(_s2);
			_md->SetOption3(_s3);

			return 0;
		}
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MsgCommon_DataFinished(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "MsgCommon_DataFinished");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommon_DataFinished");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		NoticeCommon* _md = _player->GetNoticeData();
		if (_md != nullptr)
		{
			_md->NoticeFinish();

			return 0;
		}
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MsgCommon_SendToClient(lua_State * ls)
{
	_safe_guard_begin;
	
	MacroCheckParamCount(ls, 1, "MsgCommon_SendToClient");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommon_SendToClient");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	_player->SendNoticeCommonToClient();

	return 0;

	_safe_guard_end;

	return 0;
}


//-------------------------------------------------------------------------------
int32_t MsgCommonEx_DataStart(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "MsgCommonEx_DataStart");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataStart");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	NoticeCommonEx* _md = _player->GetNoticeExData();
	if (nullptr == _md)
	{
		return 0;
	}
	_safe_check(_md);
	
	_md->NoticeStart();

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MsgCommonEx_DataSet(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 11, "MsgCommonEx_DataSet");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");

	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");

	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataSet");


	MacroIsString(ls, ++_pos, "MsgCommonEx_DataSet");
	MacroIsString(ls, ++_pos, "MsgCommonEx_DataSet");
	MacroIsString(ls, ++_pos, "MsgCommonEx_DataSet");


	_pos = 0;
	uint32_t _uid = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	uint32_t _v1 = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	uint32_t _v2 = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	uint32_t _v3 = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	
	uint32_t _v4 = (uint32_t)MacroGetNumberArgument(ls, ++_pos);//!42亿截断(21)，小手勿动！

	uint32_t _v5 = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	uint32_t _v6 = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	uint32_t _v7 = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	const char* _s1 = MacroGetStringArgument(ls, ++_pos);

	const char* _s2 = MacroGetStringArgument(ls, ++_pos);

	const char* _s3 = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	NoticeCommonEx* _md = _player->GetNoticeExData();
	if (nullptr == _md)
	{
		return 0;
	}
	_safe_check(_md);

	_md->SetUserVal1(_v1);
	_md->SetUserVal2(_v2);
	_md->SetUserVal3(_v3);
	_md->SetUserVal4(_v4);
	_md->SetUserVal5(_v5);
	_md->SetUserVal6(_v6);
	_md->SetUserVal7(_v7);
	_md->SetOption1(_s1);
	_md->SetOption2(_s2);
	_md->SetOption3(_s3);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MsgCommonEx_DataFinished(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "MsgCommonEx_DataFinished");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_DataFinished");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	NoticeCommonEx* _md = _player->GetNoticeExData();
	if (nullptr == _md)
	{
		return 0;
	}
	_safe_check(_md);

	_md->NoticeFinish();

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MsgCommonEx_SendToClient(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "MsgCommonEx_SendToClient");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MsgCommonEx_SendToClient");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);


	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	_player->SendNoticeCommonExToClient();

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Title_SetToUser(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 4, "Title_SetToUser");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Title_SetToUser");
	MacroIsNumber(ls, ++_pos, "Title_SetToUser");
	MacroIsNumber(ls, ++_pos, "Title_SetToUser");
	MacroIsNumber(ls, ++_pos, "Title_SetToUser");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _titleId = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _validTime = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _scriptId = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	_safe_check(_player);

	TitleSystem* _pTitle = _player->GetTitleSystem();
	_safe_check(_pTitle);

	int32_t _idx = _pTitle->GetValidTitlePosIndex();
	if (-1 != _idx)
	{
		_pTitle->SetTitleId(_idx, _titleId);
		_pTitle->SetDeadLine(_idx, _validTime);
		_pTitle->SetPosUsed(_idx);
		_pTitle->SetTitleScriptId(_idx, _scriptId);
	}

	//	通知前端称号列表更新
	_player->GetTitleList();

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Title_ClearOneTitleAndSendEmail(lua_State * ls)
{
	_safe_guard_begin;

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Title_GetOutOfDateTitleIndex(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Backpack_GetItemCountByItemId");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Backpack_GetItemCountByItemId");
	MacroIsNumber(ls, ++_pos, "Backpack_GetItemCountByItemId");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _game_time = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		MacroPushInteger(ls, -1);
		return 1;
	}
	_safe_check(_player);

	TitleSystem* _pTitleSys = _player->GetTitleSystem();
	_safe_check(_pTitleSys);

	//检查过期称号索引
	int32_t _titleIdx = _pTitleSys->GetOutOfDateTitleIndex(_game_time);

	MacroPushInteger(ls, _titleIdx);
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Backpack_GetItemCountByItemId(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Backpack_GetItemCountByItemId");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Backpack_GetItemCountByItemId");
	MacroIsNumber(ls, ++_pos, "Backpack_GetItemCountByItemId");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _itemId = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		MacroPushInteger(ls, -1);
		return 1;
	}
	_safe_check(_player);

	MacroPushInteger(ls, _player->GetItemCountByItemId(_itemId));
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Vip_GetSweepRewardCount(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Vip_GetSweepRewardCount");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Vip_GetSweepRewardCount");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		MacroPushInteger(ls, -1);
		return 1;
	}
	_safe_check(_player);

	VipCnfgData* _pVipData = VipCnfgTablePtr->GetVipCnfgDataById(_player->GetVip());
	_safe_check(_pVipData);

	uint32_t sweepNum = _pVipData->m_sweep;

	MacroPushInteger(ls, sweepNum);
	return 1;

	_safe_guard_end;
	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Vip_GetRewardTaskMaxCount(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Vip_GetRewardTaskCount");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Vip_GetRewardTaskCount");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		MacroPushInteger(ls, -1);
		return 1;
	}
	_safe_check(_player);

	VipCnfgData* _pVipData = VipCnfgTablePtr->GetVipCnfgDataById(_player->GetVip());
	_safe_check(_pVipData);

	uint32_t rewardTaskCount = _pVipData->m_reward_task;

	MacroPushInteger(ls, rewardTaskCount);
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Vip_GetHornRewardCount(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Vip_GetHornRewardCount");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Vip_GetHornRewardCount");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		MacroPushInteger(ls, -1);
		return 1;
	}
	_safe_check(_player);

	VipCnfgData* _pVipData = VipCnfgTablePtr->GetVipCnfgDataById(_player->GetVip());
	_safe_check(_pVipData);

	uint32_t HornNum = _pVipData->m_horn;

	MacroPushInteger(ls, HornNum);
	return 1;

	_safe_guard_end;
	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Random_IntValue(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Random_IntValue");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Random_IntValue");
	MacroIsNumber(ls, ++_pos, "Random_IntValue");

	_pos = 0;
	int32_t _max = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _min = MacroGetIntegerArgument(ls, ++_pos);

	uint32_t randValue = CRandomManager::GetInstance().RandomIntC11(_max, _min);

	MacroPushInteger(ls, randValue);
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Game_CurrentTime(lua_State * ls)
{
	_safe_guard_begin;

	uint32_t _cur_time = CUR_FULLDAY;

	MacroPushInteger(ls, _cur_time);
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Game_DayTime(lua_State *ls)
{
	_safe_guard_begin;

	uint32_t _day_time = CUR_DAY;

	MacroPushInteger(ls, _day_time);
	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
//int32_t tracelog(lua_State * ls)
//{
//	_safe_guard_begin;
//
//	MacroCheckParamCount(ls, 1, "tracelog");
//
//	uint32_t _pos = 0;
//	MacroIsNumber(ls, ++_pos, "tracelog");
//
//	_pos = 0;
//	int32_t _prm_1 = MacroGetIntegerArgument(ls, ++_pos);
//
//	MacroPushInteger(ls, 1);
//	return 1;
//
//	_safe_guard_end;
//
//	MacroPushInteger(ls, -1);
//	return 1;
//}

//-------------------------------------------------------------------------------
int32_t MissionOfferReward_SetElseMissionInvalidState(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 4, "MissionOfferReward_SetElseMissionInvalidState");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_SetElseMissionInvalidState");
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_SetElseMissionInvalidState");
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_SetElseMissionInvalidState");
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_SetElseMissionInvalidState");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _flag_idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _flag_val = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	MissionSystem* _ms = _player->GetMissionSystem();
	_ms->SetElseOfferRewardMissionInvalidState(_idx, _flag_idx, _flag_val);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MissionOfferReward_ResetElseMissionInvalidState(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 4, "MissionOfferReward_ResetElseMissionInvalidState");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_ResetElseMissionInvalidState");
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_ResetElseMissionInvalidState");
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_ResetElseMissionInvalidState");
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_ResetElseMissionInvalidState");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _flag_idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _flag_val = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	MissionSystem* _ms = _player->GetMissionSystem();
	_ms->ResetElseOfferRewardMissionInvalidState(_flag_idx, _flag_val);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t MissionOfferReward_UpdateListByOneItem(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "MissionOfferReward_UpdateListByOneItem");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "MissionOfferReward_UpdateListByOneItem");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	_safe_check(_player);

	//_player->UpdateOfferRewardMissionListByOneItem();

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Mission_GetRewardTableItemData(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Mission_GetRewardTableData");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Mission_GetRewardTableData");
	MacroIsNumber(ls, ++_pos, "Mission_GetRewardTableData");

	_pos = 0;
	int32_t _Id = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _posIdx = MacroGetIntegerArgument(ls, ++_pos);

	taskRewardData * pTable = TaskRewardCnfgTablePtr->GetTaskRewardDataById(_Id);
	_safe_check(pTable);

	uint32_t rewardId = pTable->mItemReward[_posIdx].rewardId;
	uint32_t rewardNum = pTable->mItemReward[_posIdx].rewardNum;

	MacroPushInteger(ls, rewardId);
	MacroPushInteger(ls, rewardNum);
	return 2;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Mission_GetRewardTableItemCount(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Mission_GetRewardTableItemCount");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Mission_GetRewardTableItemCount");

	_pos = 0;
	int32_t _Id = MacroGetIntegerArgument(ls, ++_pos);

	taskRewardData * pTable = TaskRewardCnfgTablePtr->GetTaskRewardDataById(_Id);
	_safe_check(pTable);

	uint32_t count = pTable->mItemReward.size();

	MacroPushInteger(ls, count);
	return 1;

	_safe_guard_end;

	return 0;
}
#ifdef _MSC_VER
#include <cstdio>
#include "Windows.h"
#endif // _MSC_VER

//-------------------------------------------------------------------------------


//-------------------------------------------------------------------------------
int32_t CSendToClient(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "CSendToClient");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CSendToClient");
	MacroIsNumber(ls, ++_pos, "CSendToClient");
	MacroIsString(ls, ++_pos, "CSendToClient");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _msgId = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		_player->SendToClient(&_val, _msgId);
		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

int32_t CSendToClientByPlayerID(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "CSendToClientByPlayerID");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CSendToClientByPlayerID");
	MacroIsNumber(ls, ++_pos, "CSendToClientByPlayerID");
	MacroIsString(ls, ++_pos, "CSendToClientByPlayerID");

	_pos = 0;
	uint32_t _playerid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _msgId = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_playerid);
	if (_player != nullptr)
	{
		_player->SendToClient(&_val, _msgId);
		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
string int_to_string(int data)
{
	stringstream str;
	str << data;
	return str.str();
}

// 设置标签红点数据
// check_red_flag_label
int32_t CCheckRedFlagLabel(lua_State * ls)
{
	unsigned int ret = 0;
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "CCheckRedFlagLabel");
	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagLabel1");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagLabel2");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagLabel3");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagLabel4");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagLabel5");

	_pos = 0;
	unsigned int _uid = MacroGetIntegerArgument(ls, ++_pos);		// 玩家id
	unsigned int label_id = MacroGetIntegerArgument(ls, ++_pos);	// 标签id
	int label_change = MacroGetIntegerArgument(ls, ++_pos);			// 标签数据
	unsigned int msg_id = MacroGetIntegerArgument(ls, ++_pos);		// 消息id (未用)
	int label_reset = MacroGetIntegerArgument(ls, ++_pos);			// 数据标记: 0=label_change是该变量 1=label_change是设置量

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player == nullptr)
	{
		return 0;
	}
	unsigned int player_id = _player->GetPlayerId();

	red_flag * red_ptr = RedFlagMgrPtr->get_red_flag(player_id);

	vector<red_flag_label_change_node>  label_change_vec;
	if (red_ptr != NULL)
	{
		red_ptr->label_change(label_id, label_change, label_change_vec, label_reset);
	}

	string str;
	Json::Value rt_value;
	ret = label_change_vec.size();
	if (ret != 0)
	{
		for ( size_t i = 0; i < ret; ++i)
		{
			Json::Value temp_value;
			temp_value["label_id"] = label_change_vec[i].label_id;
			temp_value["label_change"] = label_change_vec[i].label_red_change;

			rt_value.append(temp_value);
		}

		str = JsonWriter(rt_value);
	}

	if (rt_value.empty())
	{
		str = "0";
	}
	
	// 返回标签变动记录(JSON)
	MacroPushString(ls,str.c_str());

	_safe_guard_end;
	return 1;
}
//-------------------------------------------------------------------------------
// 检查红点的定时器
// LuaAPI: check_red_flag_time
// 定时到后, 执行 update_time_fun
// --> Player::update_by_time
// --> (Lua)S50001_update_by_time
int32_t CCheckRedFlagTime(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "CCheckRedFlagTime");
	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagTime");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagTime");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagTime");

	_pos = 0;
	unsigned int _uid = MacroGetIntegerArgument(ls, ++_pos);
	unsigned int check_time = MacroGetIntegerArgument(ls, ++_pos);	// 检查时间(时间戳)
	unsigned int label_id = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player == nullptr)
	{
		return 0;
	}
	unsigned int player_id = _player->GetPlayerId();

	RedFlagMgrPtr->insert_update_time(check_time, label_id, player_id);
	

	_safe_guard_end;
	return 0;
}
// lcl 2017-11-23 定时器内部使用这个函数处理数据
void update_time_fun(red_flag_time_node data_value)
{
	if (data_value.label_id == 0) // 凌晨刷新，全部在线的都刷新
	{
		
		CSceneLogic::GetInstance().update_time_to_online_player(data_value.label_id);
		unsigned int tomorrow_time = red_flag_manager::get_tomorrow_time(0);
		RedFlagMgrPtr->insert_update_time(tomorrow_time,0,0);	
	}
	else
	{
		Player* player_ptr = CSceneLogic::GetInstance().GetPlayerByPlayerID(data_value.player_id);
		if (player_ptr == NULL)
		{
			return;
		}

		player_ptr->update_by_time(MapSlot::GetInstance().GetLuaManagerPtr(),data_value.label_id);
	}
}
//-------------------------------------------------------------------------------
// lcl 2017-11-17 好友头像红点lua回调函数
int32_t CCheckRedFlagFriend(lua_State * ls)
{
	unsigned int ret = 0;
	_safe_guard_begin;

	MacroCheckParamCount(ls, 4, "CCheckRedFlagFriend");
	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagFriend");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagFriend");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagFriend");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagFriend");

	_pos = 0;
	unsigned int _uid = MacroGetIntegerArgument(ls, ++_pos);
	unsigned int friend_id = MacroGetIntegerArgument(ls, ++_pos);
	int friend_change = MacroGetIntegerArgument(ls, ++_pos);
	int friend_type = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player == nullptr)
	{
		return 0;
	}
	unsigned int player_id = _player->GetPlayerId();

	red_flag * red_ptr = RedFlagMgrPtr->get_red_flag(player_id);

	if (red_ptr != NULL)
	{
		ret = red_ptr->check_friend(friend_id, friend_change,friend_type);
	}

	MacroPushInteger(ls, ret);

	_safe_guard_end;
	return 1;
}
//-------------------------------------------------------------------------------
// lcl 2017-11-17 删除红点lua回调函数
int32_t CDeleteRedFlagLabel(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "CDeleteRedFlagLabel");
	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CDeleteRedFlagLabel");

	_pos = 0;
	unsigned int _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player == nullptr)
	{
		return 0;
	}
	unsigned int player_id = _player->GetPlayerId();

	RedFlagMgrPtr->delete_red_flag(player_id);

	_safe_guard_end;
	return 0;
}

//-------------------------------------------------------------------------------
// 设置单个英雄的红点数据
// check_red_flag_hero
int32_t CCheckRedFlagHero(lua_State * ls)
{
	unsigned int ret = 0;
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "CCheckRedFlagHero");
	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagHero");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagHero");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagHero");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagHero");
	MacroIsNumber(ls, ++_pos, "CCheckRedFlagHero");

	_pos = 0;
	unsigned int _uid = MacroGetIntegerArgument(ls, ++_pos);					// 玩家id
	unsigned int hero_id = MacroGetIntegerArgument(ls, ++_pos);					// 英雄id
	unsigned int hero_label_id = MacroGetIntegerArgument(ls, ++_pos);			// 英雄所属的类别
	unsigned int hero_change_type = MacroGetIntegerArgument(ls, ++_pos);		// 英雄红点的子项 1=升级 2=升星 3=突破
	unsigned int hero_change_type_data = MacroGetIntegerArgument(ls, ++_pos);	// 值

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	Json::Value rt_value;
	if (_player != nullptr)
	{
		unsigned int player_id = _player->GetPlayerId();

		red_flag * red_ptr = RedFlagMgrPtr->get_red_flag(player_id);

		int hero_label_change = 0;

		if (red_ptr != NULL)
		{
			// 保存英雄的红点计数
			red_ptr->change_hero(hero_id, hero_label_id, hero_change_type, hero_change_type_data, hero_label_change);
			if (hero_label_change != 0)
			{
				rt_value["hero"] = hero_label_change;	// 返回值，英雄及标签红点，0 表示无影响；1表示显示红点，-1表示取消红点

				// 对标签的影响
				vector<red_flag_label_change_node> label_change_vec;
				red_ptr->label_change(hero_label_id, hero_label_change, label_change_vec, 0);

				if (label_change_vec.size() != 0)
				{
					Json::Value label_vl;
					for (size_t i = 0; i < label_change_vec.size(); ++i)
					{
						Json::Value temp_value;
						temp_value["label_id"] = label_change_vec[i].label_id;
						temp_value["label_change"] = label_change_vec[i].label_red_change;

						label_vl.append(temp_value);
					}

					rt_value["label"] = label_vl;
				}
			}
		}
	}

	std::string str = "0";
	if (!rt_value.empty())
	{
		str = JsonWriter(rt_value);
	}

	// 返回标签变被动记录(JSON)
	MacroPushString(ls, str.c_str());
	

	_safe_guard_end;
	return 1;
}

int32_t CReadJsonFile(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "CReadJsonFile");

	uint32_t _pos = 0;
	MacroIsString(ls, ++_pos, "CReadJsonFile");

	_pos = 0;
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	Json::Value vv = ReadJsonFile(_val);
	std::string str = JsonWriter(vv);

	MacroPushString(ls, str.c_str())
	return 1;

	_safe_guard_end;

	return 0;
}

int32_t CSendMsgNoitfyToPlayer(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "CSendMsgNoitfyToPlayer");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CSendMsgNoitfyToPlayer");
	MacroIsString(ls, ++_pos, "CSendMsgNoitfyToPlayer");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		CMsgCode::SendMsgCodeToPlayer(*_player, _val);
		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

int32_t CSendMsgNoitfyToPlayerByPlayerId(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "CSendMsgNoitfyToPlayer");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CSendMsgNoitfyToPlayer");
	MacroIsString(ls, ++_pos, "CSendMsgNoitfyToPlayer");

	_pos = 0;
	int32_t _playerId = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_playerId);
	if (_player != nullptr)
	{
		CMsgCode::SendMsgCodeToPlayer(*_player, _val);
		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

int32_t CSendMsgNoitfyToAllPlayer(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "CSendMsgNoitfyToAllPlayer");

	uint32_t _pos = 0;
	MacroIsString(ls, ++_pos, "CSendMsgNoitfyToAllPlayer");

	_pos = 0;
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	CMsgCode::SendMsgCodeToAllPlayer(_val);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_GetSceneInfoByPlayerIdx(lua_State * ls)
{
	_safe_guard_begin;

	printf("Player_GetSceneInfoByPlayerIdx start.\n");

	MacroCheckParamCount(ls, 1, "Player_GetSceneInfoByPlayerIdx");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_GetSceneInfoByPlayerIdx");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		printf("Player_GetSceneInfoByPlayerIdx: nullptr == _player.\n");
		printf("Player_GetSceneInfoByPlayerIdx end.\n");
		return 0;
	}
	if (_player != nullptr)
	{
		uint32_t _scene_id = _player->GetSceneId();
		double _pos_x = 0;// _player->GetPosX();
		double _pos_y = 0;// _player->GetPosY();
		double _pos_z = 0;// _player->GetPosZ();

		printf("_uid:[%d],_scene_id:[%d],_pos_x:[%f], _pos_y:[%f], _pos_z:[%f]\n",
			_uid, _scene_id, _pos_x, _pos_y, _pos_z);

		MacroPushInteger(ls, _scene_id);
		MacroPushNumber(ls, _pos_x);
		MacroPushNumber(ls, _pos_y);
		MacroPushNumber(ls, _pos_z);
		printf("Player_GetSceneInfoByPlayerIdx end.\n");
		return 4;
	}

	printf("Player_GetSceneInfoByPlayerIdx end.\n");

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_SetSceneInfoByPlayerIdx(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "Player_GetSceneInfoByPlayerIdx");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_GetSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_GetSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_GetSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_GetSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_GetSceneInfoByPlayerIdx");

	_pos = 0;
	uint32_t _player_idx = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	uint32_t _scene_id = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	double _pos_x = MacroGetNumberArgument(ls, ++_pos);
	double _pos_y = MacroGetNumberArgument(ls, ++_pos);
	double _pos_z = MacroGetNumberArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_player_idx);
	if (_player == nullptr)
	{
		return 0;
	}
	
	PlayerRuntimeInfo* _pri = _player->GetPlayerRuntimeInfo();
	if (_pri == nullptr)
	{
		return 0;
	}

	//printf("C++ Player_SetSceneInfoByPlayerIdx %d; %d; %f; %f; %f\n",
	//	_player_idx, _scene_id, _pos_x, _pos_y, _pos_z);

	if (_scene_id == 0)
	{
		LOG_WARN("default","Player_SetSceneInfoByPlayerIdx error. _scene_id==0");
	}

//	_player->SetSceneId(_scene_id);
	//_player->SetPosX(_pos_x);
	//_player->SetPosY(_pos_y);
	//_player->SetPosZ(_pos_z);

	//_player->SetPlayerState(PlayerState::ps_pre_enter_scene);

	//	跳转场景后的出生点位置
	_pri->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::HOMEPLACE_POS_X), (uint32_t)(_pos_x));

	_pri->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::HOMEPLACE_POS_Y), (uint32_t)(_pos_y));

	_pri->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::HOMEPLACE_POS_Z), (uint32_t)(_pos_z));

//player->ClearRockerState();	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_GetLastSceneInfoByPlayerIdx(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Player_GetLastSceneInfoByPlayerIdx");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_GetLastSceneInfoByPlayerIdx");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player == nullptr)
	{
		return 0;
	}

	PlayerRuntimeInfo* _pri = _player->GetPlayerRuntimeInfo();
	if (_pri == nullptr)
	{
		return 0;
	}

	uint32_t _scene_id = _pri->m_temp_int_data.GetValue(
		(uint16_t)(player_temp_int::LAST_SCENE_ID));
	
	double _pos_x = (int32_t)_pri->m_temp_double_data.GetValue(
		(uint16_t)(player_temp_double::LAST_SCENE_POS_X));
	
	double _pos_y = (int32_t)_pri->m_temp_double_data.GetValue(
		(uint16_t)(player_temp_double::LAST_SCENE_POS_Y));
	
	double _pos_z = (int32_t)_pri->m_temp_double_data.GetValue(
		(uint16_t)(player_temp_double::LAST_SCENE_POS_Z));

	MacroPushInteger(ls, _scene_id);
	MacroPushNumber(ls, _pos_x);
	MacroPushNumber(ls, _pos_y);
	MacroPushNumber(ls, _pos_z);

	return 4;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Player_SetLastSceneInfoByPlayerIdx(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "Player_SetLastSceneInfoByPlayerIdx");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_SetLastSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_SetLastSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_SetLastSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_SetLastSceneInfoByPlayerIdx");
	MacroIsNumber(ls, ++_pos, "Player_SetLastSceneInfoByPlayerIdx");

	_pos = 0;
	uint32_t _player_idx = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	uint32_t _scene_id = MacroGetUnsignedIntegerArgument(ls, ++_pos);
	double _pos_x = MacroGetNumberArgument(ls, ++_pos);
	double _pos_y = MacroGetNumberArgument(ls, ++_pos);
	double _pos_z = MacroGetNumberArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_player_idx);
	if (_player == nullptr)
	{
		return 0;
	}

	PlayerRuntimeInfo* _pri = _player->GetPlayerRuntimeInfo();
	if (_pri == nullptr)
	{
		MacroPushInteger(ls, -1);
		return 1;
	}

	//	指定跳转需要保存当前场景的id以及坐标
	_pri->m_temp_int_data.SetValue(
		(uint16_t)(player_temp_int::LAST_SCENE_ID), _scene_id);
	
	_pri->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::LAST_SCENE_POS_X), (uint32_t)(_pos_x));
	
	_pri->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::LAST_SCENE_POS_Y), (uint32_t)(_pos_y));
	
	_pri->m_temp_double_data.SetValue(
		(uint16_t)(player_temp_double::LAST_SCENE_POS_Z), (uint32_t)(_pos_z));

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
// 检查帐号返回消息，进入游戏前必发
int32_t Player_SendCheckAccountRet(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Player_SendCheckAccountRet");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_SendCheckAccountRet");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		_player->SendCheckAccountRetToClient();

		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}
//-------------------------------------------------------------------------------
// 角色聊天消息返回
int32_t Player_SendChatMsgNotify(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "Player_SendChatMsgNotify");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_SendChatMsgNotify");
	MacroIsNumber(ls, ++_pos, "Player_SendChatMsgNotify");
	MacroIsString(ls, ++_pos, "Player_SendChatMsgNotify");
	MacroIsString(ls, ++_pos, "Player_SendChatMsgNotify");
	MacroIsNumber(ls, ++_pos, "Player_SendChatMsgNotify");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _types = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);
	int32_t _ct = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _destId = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (_player != nullptr)
	{
		_player->SendPlayerChatMessageNotifyToClient(_types, _val, _ct, _destId);

		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
//	用户登录结束
int32_t Player_LoginFinished(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Player_LoginFinished");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_LoginFinished");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	manager_helper::SetPlayerLoginFinished(_uid);

	return 0; 

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_EnterGame(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Player_EnterGame");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_EnterGame");

	_pos = 0;
	int32_t _pid = MacroGetIntegerArgument(ls, ++_pos);

	manager_helper::PlayerEnterGame(_pid);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_LeaveGame(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Player_LeaveGame");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_LeaveGame");

	_pos = 0;
	int32_t _pid = MacroGetIntegerArgument(ls, ++_pos);

	manager_helper::PlayerLeaveGame(_pid);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_EnterScene(lua_State * ls)
{
	_safe_guard_begin;
	MacroCheckParamCount(ls, 1, "Player_EnterScene");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_EnterScene");

	_pos = 0;
	int32_t _pid = MacroGetIntegerArgument(ls, ++_pos);

	manager_helper::PlayerEnterScene(_pid);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_LeaveScene(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Player_LeaveScene");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_LeaveScene");
	MacroIsNumber(ls, ++_pos, "Player_LeaveScene");

	_pos = 0;
	int32_t _pid = MacroGetIntegerArgument(ls, ++_pos);
	uint32_t _from = MacroGetUnsignedIntegerArgument(ls, ++_pos);

	manager_helper::PlayerLeaveScene(_pid, _from);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Init_PlayerDefaultTitle(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Init_PlayerDefaultTitle");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Init_PlayerDefaultTitle");
	MacroIsNumber(ls, ++_pos, "Init_PlayerDefaultTitle");
	MacroIsNumber(ls, ++_pos, "Init_PlayerDefaultTitle");

	_pos = 0;
	int32_t _pid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _type = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _param = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_pid);
	_safe_check(_player);

	//_player->GetPlayerTitleByType(_type, _param);
	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
//	副本相关
//-------------------------------------------------------------------------------
int32_t Dungeon_UpdateStar(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 5, "Dungeon_UpdateStar");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Dungeon_UpdateStar");
	MacroIsNumber(ls, ++_pos, "Dungeon_UpdateStar");
	MacroIsNumber(ls, ++_pos, "Dungeon_UpdateStar");
	MacroIsNumber(ls, ++_pos, "Dungeon_UpdateStar");
	MacroIsNumber(ls, ++_pos, "Dungeon_UpdateStar");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _idx = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _star = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _type = MacroGetIntegerArgument(ls, ++_pos);//普通-精英-活动
	int32_t _msnId = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	_player->SetDungeonStar(_idx, _star);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
// 
int32_t Player_SetRedPointNotify(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Player_SetRedPointNotify");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_SetRedPointNotify");
	MacroIsString(ls, ++_pos, "Player_SetRedPointNotify");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	std::string _rpp = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if ( nullptr == _player )
	{
		return 0;
	}
	_safe_check(_player);

	_player->SetRedPointNotify(_rpp);

	return 0;

	_safe_guard_end;

	return 0;
}

// 自适应选服配置
int32_t Common_GetConfigApposite(lua_State *ls)
{
	_safe_guard_begin;


	int32_t apposite = (int32_t)GameHostManager::GetInstance().GetGameHostApposite();

	// 返回 apposite
	MacroPushInteger(ls, apposite);

	return 1;

	_safe_guard_end;
	return 0;
}

// 获取 zone_Id
int32_t Common_GetServerZoneId(lua_State *ls)
{
	_safe_guard_begin;

	int32_t zoneId = GameHostManager::GetInstance().GetServerZoneId();
	MacroPushInteger(ls, zoneId);

	return 1;

	_safe_guard_end;
	return 0;
}

// 获取 area_Id
int32_t Common_GetServerAreaId(lua_State *ls)
{
	_safe_guard_begin;

	int32_t areaId = GameHostManager::GetInstance().GetServerAreaId();
	MacroPushInteger(ls, areaId);

	return 1;

	_safe_guard_end;
	return 0;
}

// 获取 host_Id 的ip:port
int32_t Common_GetGameHost(lua_State *ls)
{
	_safe_guard_begin;

	int32_t hostId = 0;

	int32_t _count = lua_gettop((ls));
	if (_count >= 1)
	{
		hostId = MacroGetIntegerArgument(ls, 1);
	}

	std::string _ip = GameHostManager::GetInstance().GetGameHostIp(hostId);
	int32_t _port = (int32_t)GameHostManager::GetInstance().GetGameHostListenPort(hostId);

	// 返回 hostId, ip, port
	MacroPushInteger(ls, hostId);
	MacroPushString(ls, _ip.c_str());
	MacroPushInteger(ls, _port);

	return 3;

	_safe_guard_end;
	return 0;
}

//-------------------------------------------------------------------------------
// 获取在线用户人数
int32_t Common_GetOnlinePlayerCount(lua_State *ls)
{
	_safe_guard_begin;

	int32_t count = CSceneLogic::GetInstance().GetOnlineCount();
	MacroPushInteger(ls, count);

	return 1;

	_safe_guard_end;

	MacroPushInteger(ls, -1);
	return 1;
}

//-------------------------------------------------------------------------------
int32_t Player_SetCurrentViewGroup(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 2, "Player_SetCurrentViewGroup");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_SetCurrentViewGroup");
	MacroIsNumber(ls, ++_pos, "Player_SetCurrentViewGroup");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _viewgroup_id = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t Player_ResetLastViewGroup(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "Player_ResetLastViewGroup");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_ResetLastViewGroup");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(_uid);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	// 保存老的可视组和场景ID
	uint32_t _last_viewgroup_id = _player->GetPlayerRuntimeInfo()->m_temp_int_data.GetValue((uint16_t)player_temp_int::LAST_VIEWGROUP);


	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t GM_SendChatMsgNotify(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "GM_SendChatMsgNotify");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "GM_SendChatMsgNotify");
	MacroIsString(ls, ++_pos, "GM_SendChatMsgNotify");
	MacroIsNumber(ls, ++_pos, "GM_SendChatMsgNotify");

	_pos = 0;
	int32_t _types = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);
	int32_t _ct = MacroGetIntegerArgument(ls, ++_pos);

	CSceneLogic::GetInstance().SendGmMessageToOnlinePlayer(_types, _val, _ct);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t GM_SendMarqueeMsgNotify(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 4, "GM_SendMarqueeMsgNotify");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "GM_SendMarqueeMsgNotify");
	MacroIsNumber(ls, ++_pos, "GM_SendMarqueeMsgNotify");
	MacroIsNumber(ls, ++_pos, "GM_SendMarqueeMsgNotify");
	MacroIsString(ls, ++_pos, "GM_SendMarqueeMsgNotify");

	_pos = 0;
	int32_t _spn = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _tp = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _py = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	LOG_DEBUG("default","GM_SendMarqueeMsgNotify() -> _val:%s", _val.c_str());

	CSceneLogic::GetInstance().SendGmMarqueeToOnlinePlayer(_spn, _tp, _val, _py);

	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
int32_t CSendToClientBySocketId(lua_State * ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "CSendToClientBySocketId");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "CSendToClientBySocketId");
	MacroIsNumber(ls, ++_pos, "CSendToClientBySocketId");
	MacroIsString(ls, ++_pos, "CSendToClientBySocketId");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _msgId = MacroGetIntegerArgument(ls, ++_pos);
	std::string _val = MacroGetStringArgument(ls, ++_pos);

	if (_uid > 0)
	{
		GameServer::GetInstance().client_msg_dispatch(_val, _uid, _msgId);
		return 0;
	}

	return 0;

	_safe_guard_end;

	return 0;
}

int32_t Player_SetSinglePlayerHeroInfoByPlayerId(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 3, "Player_SetSingleHeroInfo");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "Player_SetSingleHeroInfo");
	MacroIsNumber(ls, ++_pos, "Player_SetSingleHeroInfo");
	MacroIsString(ls, ++_pos, "Player_SetSingleHeroInfo");

	_pos = 0;
	int32_t playerId = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _heroId = MacroGetIntegerArgument(ls, ++_pos);
	std::string _heroInfo = MacroGetStringArgument(ls, ++_pos);

	Player* _player = CSceneLogic::GetInstance().GetPlayerByPlayerID(playerId);
	if (nullptr == _player)
	{
		return 0;
	}
	_safe_check(_player);

	Json::Value jm;
	JsonReader(_heroInfo, jm);

	_player->SetOneHeroInfo(_heroId, jm);

	return 0;

	_safe_guard_end;

	return 0;
}

// 玩家行为日志
// PlayerActionLog(accountId, playerId, actionType, actionParam1, actionParam2, strDesc)
int32_t PlayerActionLog(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 6, "PlayerActionLog");

	uint32_t _pos = 0;
	MacroIsNumber(ls, ++_pos, "PlayerActionLog");
	MacroIsNumber(ls, ++_pos, "PlayerActionLog");
	MacroIsNumber(ls, ++_pos, "PlayerActionLog");
	MacroIsNumber(ls, ++_pos, "PlayerActionLog");
	MacroIsNumber(ls, ++_pos, "PlayerActionLog");
	MacroIsString(ls, ++_pos, "PlayerActionLog");

	_pos = 0;
	int32_t _uid = MacroGetIntegerArgument(ls, ++_pos);			// account
	int32_t _playerId = MacroGetIntegerArgument(ls, ++_pos);
	int32_t _actionType = MacroGetIntegerArgument(ls, ++_pos);
	double _actionParam1 = MacroGetNumberArgument(ls, ++_pos);
	double _actionParam2 = MacroGetNumberArgument(ls, ++_pos);
	std::string _strDesc = MacroGetStringArgument(ls, ++_pos);


	int32_t areaId = GameHostManager::GetInstance().GetServerAreaId();
	std::string strTime = boost::posix_time::to_simple_string(boost::posix_time::second_clock::local_time());

	char strBuff[1024];

	sprintf(strBuff, "[%s] PLAYER ACTION account=%d, playerId=%d, action=%d, param1=%lg, param2=%lg, desc=%s",
		strTime.c_str(), _uid, _playerId, _actionType, _actionParam1, _actionParam2, _strDesc.c_str());

	char logFileName[512];
	sprintf(logFileName, "log/playerAction-%d-%d.log", areaId, CUR_DAY);
	FILE* lfpLogFile = fopen(logFileName, "a");
	if (lfpLogFile)
	{
		try {
			fprintf(lfpLogFile, "%s\r\n", strBuff);
		}
		catch (...)
		{
			// 写入出错
		}
		fclose(lfpLogFile);
	}

	return 0;

	_safe_guard_end;

	return 0;
}

// 获取 uuid
int32_t Get_Uuid( lua_State * ls )
{
	_safe_guard_begin;

	boost::uuids::uuid uuid=boost::uuids::random_generator()( );
	std::stringstream ss;
	ss<<uuid;

	MacroPushString( ls, ss.str().c_str() );
	ss.clear();
	return 1;

	_safe_guard_end;
	return 0;
}

//-------------------------------------------------------------------------------
// Game-Map心跳更新
int32_t G2M_UpdateHeartTime(lua_State *ls)
{
	_safe_guard_begin;

	ServerHeartMgrPtr->UpdateG2MHeart();
	return 0;

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
// webRedis
int32_t WebRedis_SetMapList(lua_State *ls)
{
	_safe_guard_begin;

	MacroCheckParamCount(ls, 1, "WebRedis_SetMapList");

	uint32_t _pos = 0;
	MacroIsString(ls, ++_pos, "WebRedis_SetMapList");

	_pos = 0;
	string strList = MacroGetStringArgument(ls, ++_pos);			// strList

	Json::Value mapItem;
	mapItem.clear();
	JsonReader(strList, mapItem);
	uint32_t count = mapItem.size();

	for (uint32_t i = 0; i < mapItem.size(); ++i)
	{
		string strip = mapItem[i]["mapIp"].asString();
		uint32_t port = atoi(mapItem[i]["mapPort"].asString().c_str());
		uint32_t mid = mapItem[i]["mapId"].asUInt();
		//WebRedisMgrPtr->AddMapConnectInfo(strip, port, mid);
	}

	_safe_guard_end;

	return 0;
}

//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------

